﻿namespace Permutation
{
    using System.Collections.Generic;
    using System.Linq;

    public class SurnamePermutation
    {
        public static List<string> Recursion(string[] mass)
        {
            List<string> rez = new List<string>();

            if (mass.Length == 0) return rez;

            if (mass.Length == 1) rez.Add(mass[0]);
            else
            {
                for (int i = 0; i < mass.Length; i++)
                {
                    var tempMass = mass.ToList();
                    tempMass.RemoveAt(i);

                    List<string> tempList = Recursion(tempMass.ToArray());
                    for (int j = 0; j < tempList.Count; j++)
                    {
                        rez.Add(mass[i] + " " + tempList[j]);
                    }
                }
            }

            return rez;
        }
    }
}
